home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: netcom.com!smryan
- From: smryan@netcom.com (@#$%!?!)
- Subject: Re: convert 4 8-bit bytes in a foat
- Message-ID: <smryanDpGp84.Fsw@netcom.com>
- Organization: The Programmer formerly known as S M Ryan
- X-Newsreader: TIN [version 1.2 PL1]
- References: <4k5pr7$bp7@nuscc.nus.sg>
- Date: Sat, 6 Apr 1996 22:31:16 GMT
- Sender: smryan@netcom6.netcom.com
-
-
- : I have 4 8-bit bytes. If I line them up in order, they actually represent
- : the 32-bit float data type version of a decimal point number. So, how do
- : I get the compiler to understand that, and print out the float number
- : instead of giving me 4 integers?
-
-
- You can generally use a union to fake out type checking:
-
- union {float f; char b[4];} coercer;
-
- And then depending on what order your machine stores bytes
-
- assert(sizeof(float)==4);
-
- coercer.b[0] = byte0; coercer.b[0] = byte3;
- ... or ...
- coercer.b[3] = byte3; coercer.b[3] = byte0;
-
- and then use
-
- ...coercer.f...
- --
- A haggard king with hungerred sigh | smryan@netcom.com PO Box 1563
- awaits the one who wanders nigh. | Cupertino, California
- With royal robe and ruined globe, | (xxx)xxx-xxxx 95015
- this phantom casts a fearful lie. | I don't use no smileys
-